<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<div id="app">
    <el-card style="width: 600px;height: 300px;
    margin: 0 auto;background-color: rgba(255,255,255,0.3)">
        <p>{{answer}}</p>
    </el-card>
    <br/>
    <el-card style="width: 600px;height: 300px;
    margin: 0 auto;background-color: rgba(255,255,255,0.3)">
    <el-form :inline="true">
        <el-form-item label="Message">
            <el-input v-model="chat.prompt" placeholder="message"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="send">查询</el-button>
        </el-form-item>
    </el-form>
    </el-card>

</div>

</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                chat:{
                    "model": "text-davinci-003",
                    "prompt": "",
                    "max_tokens": 200,
                    "temperature": 0
                },
                answer:"hello"
            }
        },
        methods:{
            send(){
                axios.post("https://api.openai.com/v1/completions",
                           v.chat,{ headers: { 'Authorization': "Bearer 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"}})
                    .then(function(result){
                        console.log(result.data.choices[0].text);
                        v.answer=result.data.choices[0].text;
                    })
            }
        }
    })
</script>
</html>